﻿using System;

namespace DataStore.Domain
{
    /// <summary>
    /// Range of numbers
    /// </summary>
    [Serializable]
    public class Range : IEquatable<Range>
    {
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public virtual Guid Id { get; set; }

        /// <summary>
        /// Gets or sets the starting number in arabic numerics.
        /// </summary>
        /// <value>The arabic start.</value>
        public virtual int ArabicStart { get; set; }
        /// <summary>
        /// Gets or sets the ending number in arabic numerics.
        /// </summary>
        /// <value>The arabic end.</value>
        public virtual int ArabicEnd { get; set; }

        /// <summary>
        /// Gets or sets the starting number in roman numerics.
        /// </summary>
        /// <value>The roman start.</value>
        public virtual string RomanStart { get; set; }
        /// <summary>
        /// Gets or sets the ending number in roman numerics.
        /// </summary>
        /// <value>The roman end.</value>
        public virtual string RomanEnd { get; set; }

        /// <summary>
        /// Gets or sets the default number format.
        /// </summary>
        /// <value>The default number format.</value>
        public virtual RangeFormat DefaultFormat { get; set; }

        #region ToString

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return string.Format("{0}-{1}", ArabicStart, ArabicEnd);
        }
        #endregion

        #region Equality

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public virtual bool Equals(Range other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id.Equals(Id);
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            return Equals(obj as Range);

        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(Range left, Range right)
        {
            return Equals(left, right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(Range left, Range right)
        {
            return !Equals(left, right);
        }

        #endregion
    }
}
